# -*- coding: utf-8 -*-

"""
Module implementing MainWindow.
"""

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
from Ui_seth_gost import Ui_MainWindow

import os
import urllib.request


class MainWindow(QMainWindow, Ui_MainWindow):
    """
    Class documentation goes here.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        """
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.thread = DownLoadThread(self)
        self.thread.sinOut.connect(self.msg)
        self.lineEdit_3.setText(os.environ.get('USERPROFILE') + "\\gost.exe")
    @pyqtSlot()
    def on_pushButton_clicked(self):
        """
        Slot documentation goes here.
        """
        self.thread.start()
    @pyqtSlot()
    def msg(self):  
        QMessageBox.information(self,"标题","消息")  
    
    @pyqtSlot()
    def on_pushButton_4_clicked(self):
        """
        Slot documentation goes here.
        """
        gostPath = os.environ.get('USERPROFILE') + "\\gost.exe"
        
        self.textEdit.setText("""DIM objShell
set objShell=wscript.createObject("wscript.shell")  
iReturn=objShell.Run("cmd.exe /C %s -L=:%s -F=%s", 0, TRUE)
""" % (gostPath, 8090, self.lineEdit_2.text()))
    
    @pyqtSlot()
    def on_pushButton_5_clicked(self):
        """
        Slot documentation goes here.
        """
        data=self.textEdit.toPlainText()
        print(data)
        startPath=os.environ.get('APPDATA')+"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\startGost.vbs"
        f=open(startPath,  'w')
        f.write(data)
        f.close()
    
    @pyqtSlot()
    def on_pushButton_6_clicked(self):
        """
        Slot documentation goes here.
        """
        os.popen(os.environ.get('APPDATA')+"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\startGost.vbs")
        QMessageBox.information(self, "提醒","启动成功")
class DownLoadThread(QThread):
    sinOut = pyqtSignal()

    def __init__(self, parent=None):
        super(DownLoadThread, self).__init__(parent)
        self.working = True
        self.num = 0

    def setMd5(self, text):
        self.md5 = text

    def run(self):
        print("on_btn_xmd5_clicked")
        #startPath=os.environ.get('APPDATA')+"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\"
        startPath = os.environ.get('USERPROFILE') + "\\gost.exe"
        urllib.request.urlretrieve("http://seth.oss-cn-shanghai.aliyuncs.com/gost.exe", startPath)
        self.sinOut.emit()
if __name__=="__main__":  
    import sys  
    app=QtWidgets.QApplication(sys.argv)  
    myshow=MainWindow()  
    myshow.show()  
    sys.exit(app.exec_())  
